<template>
    <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;新增问答</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form ref="form" label-width="120px">
                <el-form-item label="问题：">
                    <el-input v-model="question" placeholder="请输入问题名称" style="width:400px"></el-input>
                </el-form-item>
                <el-form-item label="回答内容：">
                    <div class="news-editor">
                        <!-- <editor ref="vueWangeditor" @load="editorLoad" @change="editorChange"
                                :width="editor_style.width" :height="editor_style.height"
                                :useQiniu="true" 
                                id="editor"></editor> -->
                    
                          <ueditor ref="vueWangeditor" @load="editorLoad" @change="editorChange"
                                :width="editor_style.width" :height="editor_style.height"
                                id="editor">
                        </ueditor>
 
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button style="width:100px; text-algin:center;" type="primary" @click="returnList">返  回</el-button>
                    <el-button style="width:100px; text-algin:center;" type="primary" @click="submit">确认新增</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
import {postUploadBase64,getQiniuUptoken} from '@/api/public';
import { getHelpList,postDeleteHelp,postAddHelp,postEditHelp } from '@/api/index/helpCenter'
import editor from '../../../components/common/editor.vue'
import ueditor from '../../../components/common/ueditor.vue'
export default {
    name:"helpAdd",
    data() {
        return {
            typeId:'', //当前要删除图片的类型   1封面图 2详情图  3关键词
            idx:0,//当前记录的下标
            accept: 'image/gif, image/jpeg, image/png, image/jpg', //图片上传类型
            selectedOptions:'',//选中的分类
            options:[],//分类数据
            question:'',//问题
            content:'',//回答
            editorOption: {
                placeholder: '请输入回答内容'
            },
            editorContent:'',

            editor_style: {
                width: 'auto',
                height: 'auto'
            },
            uploadImgUrl: '',
            uploadHeaders: {
                token: ''
            },
            uploadParams: {
                task_id: 0
            },
            
        }
    },
    components: {
        editor,
        ueditor
    },
    //方法
    methods: {
        //返回列表
        returnList (){
          this.$router.go(-1);
        },
        //确认发布
        submit(){
            let _this = this;
            // console.log(this.isShow);
            //先判断是否为空
            if(this.question==""){
                this.$notify.info({title: '提示',message: '请填写问题'});
                return false;
            }
            else if(this.$refs.vueWangeditor.getText().length<1){
                    this.$notify.info({title: '提示',message: '请填写问题回答'});
                return false;
            }
            else{
                //赋值参数
                let param ={};
                param.question = _this.question;
                param.content=this.$refs.vueWangeditor.getHtml();

                 postAddHelp(param).then(response=>{
                    // console.log("response");
                    if(response.code==200){
                        this.$message.success('新增问答成功');
                        this.isAddAccout = false;
                        setTimeout(function(){
                            _this.$router.push({path: '/index/helpCenter/list',query:{}});
                        },1500);
                    }else{
                        this.$notify.error({
                            title: '新增问答失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                })

            }
        },
        editorLoad(originalName, resultText) {
            // resultText 服务器端返回的text
            // originalName 上传文件名
            this.$refs.vueWangeditor.insertImg(resultText)
        },
        editorChange(a) {
//       console.log(a)
        },
    }
}
</script>
<style>
    .news-editor .wangEditor-container .wangEditor-txt{
        height: 300px !important;
    }
</style>
<style lang="stylus" scoped>
    .el-form-item .el-cascader{
        width :400px;
    }
    .el-cascader-menus .el-cascader-menu{
        width :240px
    }
</style>


